package saves.items;

import game.LScript;
import game.TextManager;
import java.util.HashMap;

public class Municao extends Item {
    private static final long serialVersionUID = 911677663321247447L;
    
    /**
     * The type of the ammuniton.
     * It can be:
     *  0 - Projectile (machine gun)
     *  1 - Missile (Missile Launcher)
     *  2 - Bomb (Bomb Dispenser)
     *  3 - Bomb with GC
     */
    private int type;
    
    public static final float[] DEFAULT_MASS = {.01f, .5f, .5f, 1f},
                                DEFAULT_VOLUME = {.001f, .01f, .01f, .015f};

    private Municao() { }
    
    public Municao(int type) {
        this.type = type;
        
        //generate name and description
        HashMap<String, Object> args = new HashMap<>();
        args.put("type", type);
        try {
            this.nome = LScript.parse(TextManager.t().AMMO_NAME, args);
            this.descricao = LScript.parse(TextManager.t().AMMO_DESC, args);
        } catch (LScript.ParsingError e) {
            System.err.println("Error in language file; invalid LScript: " + e.getLocalizedMessage()); //todo error pretty it up
        }
        
        //generate mass and volume
        this.massa = DEFAULT_MASS[type];
        this.volume = DEFAULT_VOLUME[type];
        
        //todo generate ip and ir
        this.indicePreco = this.indiceRaridade = .5f;
    }

    public int getType() {
        return type;
    }
    
    @Override
    public boolean equals(Object o) {
        if (o instanceof Municao)
            return ((Municao) o).type == this.type;
        return false;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 37 * hash + this.type;
        return hash;
    }
}
